"""
需求：请求IHRM项目的登录接口
url: http://ihrm-test.itheima.net/api/sys/login
请求方式：POST
请求体-json提交：
    登陆成功：mobile: 13800000002, password: 123456
    用户不存在：mobile: 13800002332, password: 123456
    密码错误：mobile: 13800000002, password: 123abc
"""
import unittest
import requests
from htmltestreport import HTMLTestReport


class ihrm_login(unittest.TestCase):
    def test_login_ok(self):
        url = 'http://ihrm-test.itheima.net/api/sys/login'
        info = {
            'mobile': '13800000002',
            'password': '123456'
        }
        response = requests.post(url, json=info)
        print(response.json())
        self.assertEqual(200,response.status_code)
        self.assertEqual(True,response.json().get('success'))
        self.assertEqual(10000,response.json().get('code'))
        self.assertIn('成功',response.json().get('message'))
    def test_login_user_err(self):
        url = 'http://ihrm-test.itheima.net/api/sys/login'
        info = {
            'mobile': '13800002332',
            'password': '123456'
        }
        response = requests.post(url, json=info)
        print(response.json())
        self.assertEqual(200,response.status_code)
        self.assertEqual(False,response.json().get('success'))
        self.assertEqual(20001,response.json().get('code'))
        self.assertIn('错误',response.json().get('message'))
    def test_login_pwd_err(self):
        url = 'http://ihrm-test.itheima.net/api/sys/login'
        info = {
            'mobile': '13800000002',
            'password': '123abc'
        }
        response = requests.post(url, json=info)
        print(response.json())
        self.assertEqual(200,response.status_code)
        self.assertEqual(False,response.json().get('success'))
        self.assertEqual(20001,response.json().get('code'))
        self.assertIn('错误',response.json().get('message'))
if __name__ == '__main__':
    suite = unittest.defaultTestLoader.discover('./', 'hm10*')
    report = HTMLTestReport('./ihrm登录测试报告.html', title="测试报告", description="V1.0")
    report.run(suite)


